#ifndef BIT_WIN_TESTS_COMMON_H
#define BIT_WIN_TESTS_COMMON_H

#include "bit_range.h"
Q_DECLARE_METATYPE(BitWin::BitRange)


#include "row_text.h"
#include "row_text_templates.h"

#include <QStringList>

// Helper functions - syntactic sugar for makers

template <typename T>
BitWin::PRowText fromIntegral(T value)
{
    BitWin::PRowTextMaker::FromIntegral<T> maker;
    return maker(value);
}

template <typename T>
BitWin::PRowText fromBitset(const T& value)
{
    BitWin::PRowTextMaker::FromBitset<T> maker;
    return maker(value);
}

template <typename T>
BitWin::PRowText fromLiteral(const T& value)
{
    BitWin::PRowTextMaker::FromLiteral<T> maker;
    return maker(value);
}

#define STRING_TEXT(s) (fromLiteral(QString(s)))
#define LIST_TEXT(lst) (fromLiteral(QStringList() << lst))
#define EMPTY_LIST_TEXT (fromLiteral(QStringList()))


namespace QTest
{

// NB! toString() caller should delete the data string
// (see QTest framework documentation)

template<>
char *toString(const BitWin::BitRange& range)
{
    return qstrdup(range.repr().toAscii().data());
}

template<>
char *toString(const BitWin::PRowText& text)
{
    QStringList list;
    for (int i = 0; i < text->size(); ++i)
        list.append(QString("\"%1\"").arg(text->at(i)));
    
    return qstrdup(QString("(%1)").arg(list.join(", ")).toAscii().data());
}

}

#endif
